<script setup>
    import { reactive,getCurrentInstance,watch,ref } from 'vue';

    const loading = ref(true)
    const {proxy} = getCurrentInstance();
    const playlistMsg = reactive({}) ;

    const props = defineProps(['nameMsg','homeShow'])
    watch(props,(newVal,oldVal)=>{
    loading.value=true
    const data = reactive({cat:newVal.nameMsg})
    console.log(oldVal)
    proxy.$https.hqlist(data).then(res=>{
    const getlist = res.data.playlists;
    loading.value=false
    playlistMsg.playlists = [...getlist]
    playlistMsg.playlists.forEach(res=>{
    const num = res.playCount
    res.playCount = num/100000 > 1 ? Math.floor(num/100000) + "万" : num
    })
    })
    },{immediate:true})
    
</script>
<template>
    <h2 v-show="props.homeShow">歌单</h2>
    <h2>{{ props.nameMsg }}</h2>
    <div v-show="!loading" class="song_wrp">
        <div 
        class="song_card" 
        v-for="(item,idx) in playlistMsg.playlists" 
        :key="idx"  
        @click="$router.push('/songCardDetail?id='+item.id)"
        >
            <img :src="item.coverImgUrl" alt="">
            <p>{{ item.name }}</p>
            <div class="playcount">
                <el-icon size="14px" color="white"><VideoPlay /></el-icon>
                <span>{{ item.playCount }}</span>
            </div>
        </div>
    </div>
    <p id="p" v-show="loading">加载中...</p>
</template>

<style scoped>
    .song_wrp{
        width: 100%;
        margin-bottom: 100px;
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between
    }
    .song_wrp .song_card{
        width: 18%;
        margin: 10px;
        position: relative;
    }
    .song_wrp .song_card .playcount{
        position: absolute;
        overflow: hidden;
        right: 5px;
        top: 5px;
        color: white;
        border-radius: 10px;
    }
    .song_wrp .song_card .playcount span{
        margin-left: 5px;
        vertical-align: text-bottom;
        font-size: 14px;
    }
    .song_wrp .song_card img{
        width: 100%;
        border-radius: 10px;
    }
    .song_wrp .song_card img:hover{
        cursor: pointer;
    }
    #p{
    color:pink;
    font-size: 50px;
    width: 100%;
    display: flex;
    justify-content: center;
    }
</style>